package com.ny.wlw;

// 1. 创建Vehicle基类
abstract class Vehicle {
    protected String make;
    protected String model;

    public Vehicle(String make, String model) {
        this.make = make;
        this.model = model;
    }

    // 抽象方法drive
    public abstract void drive();
}

// 2. 创建Car子类
class Car extends Vehicle {
    public Car(String make, String model) {
        super(make, model);
    }

    @Override
    public void drive() {
        System.out.println(make + " " + model + " is driving on the road.");
    }
}

// 3. 创建Bike子类
class Bike extends Vehicle {
    public Bike(String make, String model) {
        super(make, model);
    }

    @Override
    public void drive() {
        System.out.println(make + " " + model + " is riding on the bike lane.");
    }
}

public class Test1 {
    public static void main(String[] args) {
        // 4. 创建Vehicle数组并存储Car和Bike对象
        Vehicle[] vehicles = new Vehicle[4];
        vehicles[0] = new Car("Toyota", "Camry");
        vehicles[1] = new Car("Honda", "Accord");
        vehicles[2] = new Bike("Giant", "Talon");
        vehicles[3] = new Bike("Trek", "Marlin");

        // 5. 遍历数组并调用drive方法
        for (Vehicle vehicle : vehicles) {
            vehicle.drive();
        }
    }
}
